package mtm.ui.list;

import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.ListCellRenderer;

/**
 * Use to render list with color, icon, text
 * 
 */
public class JobCellRender extends JLabel implements ListCellRenderer {
	
	private Font labelFont = new Font(Font.SERIF, Font.ITALIC, 12);

	/**
	 * Constructor
	 */
	public JobCellRender() {
		// Don't paint behind the component
		setOpaque(true);
	}

	
	/**
	 * Display custom render of list's item
	 */
	public Component getListCellRendererComponent(JList list, Object value, int index,
			boolean iss, boolean chf){

		// render component
		JobItem item = (JobItem) value;
		setText( item.getValue() );
		setBackground( item.getColor() );
		setIcon( item.getIcon() );
		if ( !(item.getValue()).trim().equals("") ) {
			if( item.isHasToolTip() ) {
				setToolTipText( item.getValue() );
			}
		}
		setFont(labelFont);

		// render component when selected or not
		if (iss && !getText().trim().equals("")) {
			setBorder(BorderFactory.createLineBorder(Color.blue, 1));
		} else {
			setBorder(BorderFactory.createLineBorder(list.getBackground(), 1));
		}

		return this;
	}

}